﻿Public Class frmMetronome

    Private switch As Boolean = True

    Private Sub frmMetronome_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

#If DEBUG Then
        lblInterval.Visible = True
        lblInterval.Text = tmrBPM.Interval.ToString()
#End If

    End Sub

    Private Sub tmrBPM_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrBPM.Tick

        My.Computer.Audio.Stop()

        If switch Then
            pbBPM.Image = Nothing
            switch = False
        Else
            pbBPM.Image = My.Resources.BlueOrb
            If chkSound.Checked Then
                My.Computer.Audio.Play(My.Resources.Metronome_Click, AudioPlayMode.Background)
            End If
            switch = True
        End If

        Me.Refresh()

    End Sub

    Private Sub tbBPM_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbBPM.Scroll

        If tbBPM.Value >= 60 Then
            tmrBPM.Interval = CInt((1000 / (tbBPM.Value / 60)) / 2)
        Else
            'Ignore this, it never happens unless the trackbar's value is lowered
            'Calculation is wrong anyways, can always fix it if there is demand for less than 60 bpm
            tmrBPM.Interval = CInt(60000 - ((tbBPM.Value / 60) * 60000))
        End If

        lblBPM.Text = tbBPM.Value.ToString() & " bpm"

        lblInterval.Text = tmrBPM.Interval.ToString()

    End Sub

End Class